<?php

namespace app\admin\controller;

use Predis\Client;
use think\cache\driver\Redis;
use think\Controller;

use think\Request;
use think\Session;

//use think\Session;

class Base extends Controller
{
    public function _initialize()
    {
        $redis = new Client();

        // 获取用户cookie中的用户名
        $cname = Session::get('admin_name');

        $id = $redis->get('admin:name:' . $cname . ':id');

//        $id = $redis->get('admin:name:'.$name.':id');

        // 获取用户ip
        $ip = Request::instance()->ip();
        // 将ip转化成字串
        $strIp = ip2long($ip);

        // 判断是不是被锁定
        if(!empty($redis->get('admin:status:'.$strIp))) {
            $this->redirect('admin/login/login');
        }

        //cookie redis中没有id去登录
        if (empty($id)) {
            $this->redirect('admin/login/login');
        }

        // redis中没有密码去登录
        if(empty($redis->hget('admin:'.$id, 'pwd'))) {
            $this->redirect('admin/login/login');
        }

    }
}
